#---
# Excerpted from "Rails for PHP Developers",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material, 
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose. 
# Visit http://www.pragmaticprogrammer.com/titles/ndphpr for more book information.
#---
class EmployeesController < ApplicationController
  before_filter :find_employee, :except => [:index, :new, :create]

  
  def index
    @employees = Employee.find(:all, :order => "fname")
  end

  def show
  end
  

  
  def new
    @employee = Employee.new
  end

  def create
    @employee = Employee.new(params[:employee])

    if @employee.save 
      @current_employee  = @employee
      session[:employee] = @employee.id 

      flash[:notice] = "Successfully Signed up"
      redirect_to :action => "show", :id => @employee.id
    else
      render :action => "new"
    end
  end
  

  
  def edit
  end

  def update
    if @employee.update_attributes(params[:employee])
      flash[:notice] = 'Employee successfully updated.'
      redirect_to :action => "show", :id => @employee.id
    else
      render :action => "edit"
    end
  end

  def destroy
    @employee.destroy
    flash[:notice] = 'Employee successfully destroyed.'
    redirect_to :action => "index"
  end
  
  
  private

  def find_employee
    @employee = Employee.find(params[:id])
  end
end
